/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package chat01;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * <p>Project: jse2204 - Server
 * <p>Powered by webrx On 2022-09-29 14:50:50
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Server {
    public static void main(String[] args) {
        //List<Socket> lists = new ArrayList<>();
        try {

            //System.out.println(InetAddress.getLocalHost().getHostAddress());
            //192.168.13.249
            ServerSocket server = new ServerSocket(8080);
            Socket c = server.accept();
            System.out.println("有人上线");
            PrintWriter out = new PrintWriter(c.getOutputStream()); //发信息
            BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream())); //接信息

            while(true) {
                //先收信息
                String msg = br.readLine();
                System.out.println(msg);

                //发信息
                System.out.println("发信息：");
                String info = new Scanner(System.in).nextLine() + "\r\n";
                out.write(info);
                out.flush();
            }


            //while(true) {
            //    Socket c = server.accept();//中断
            //    lists.add(c);
            //    System.out.println("有人连线");
            //}


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
